package com.youdoneed.base;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * 根据英文生成消息文件的Code值。
 *
 * @author Ewing
 * @date 2017/4/21
 */
public class MessageCodeGen {

    public static void main(String[] args) throws Throwable {
        String string = "User name already exists";
        string = getCamelStyle(string);
        System.out.println(string);
    }

    public static String getCamelStyle(String string) {
        string = " " + string.replaceAll("[^a-zA-Z]+", " ");
        Pattern pattern = Pattern.compile("\\s+[a-zA-Z]");
        Matcher matcher = pattern.matcher(string);
        while (matcher.find()) {
            String group = matcher.group();
            string = string.replace(group, group.substring(group.length() - 1).toUpperCase());
        }
        return string;
    }

}
